﻿@model NAccounting.Models.AccountEntryDetailModel

@{
    ViewBag.Title = "Edit";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>

<script language="javascript">
    $(function () {
        var SAVE_AND_CREATE_NEW_MODE = 1;
        var SAVE_AND_CLOSE_LOTE_MODE = 2;

        var lotIsVal = @Model.LotIsValidJs;
        var canDelete = @Model.CanDelete;
        var modelId = @Model.AccountEntryId;
        var minDate = "@Model.MinDateJs";
        var maxDate = "@Model.MaxDateJs";

        $("#AccountPlanDescription").autocomplete({
            source: "/AccountPlan/GetAccountPlanByText",
            select: function (event, ui) {
                $("#AccountPlanId").val(ui.item.id);
            }
        });

        $('#AccountEntryDate').datepicker('option', { minDate: new Date(minDate), maxDate: new Date(maxDate) });

        if (!lotIsVal){
            $("#messageContainer").messageContainer({ icon: "info", message: "Não é possível gerar um lançamento para o lote selecionado pois este se encontra fechado" });
            $("form, form :input, #saveButton, #saveAndCreateNewButton, #saveAndCloseLotButtton").attr("disabled", "disabled");
            $( "#AccountEntryDate" ).datepicker( "option", "disabled", true );
        }

        if (!canDelete){
            $("#deleteButton").hide();
        }

        $("#saveButton").click(function () {
            $("form").submit();
        });

        $("#saveAndCreateNewButton").click(function () {
            $("#SaveMode").val(SAVE_AND_CREATE_NEW_MODE);
            $("form").submit();
        });
        $("#saveAndCloseLotButtton").click(function () {
            $("#SaveMode").val(SAVE_AND_CLOSE_LOTE_MODE);
            $("form").submit();
        });

        $("#deleteButton").click(function (){
            if (confirm("Deseja realmente excluir este item?")){
                window.location.href = "/AccountEntry/Delete/" + modelId
            }
        });

        $("#goToListButton").click(function (){
            window.location.href = "/AccountEntry/";
        });
    });
</script>

<div class="content-left">
    @Html.Partial("ContentLeftPartial")
</div>
<div class="content-right">

<div id="messageContainer"> </div>

<h2>Edit</h2>

<p>
    <button id="goToListButton" class="button-icon-return-icon-only">Voltar</button> | 
    <button id="saveButton" class="submit">Salvar</button>
    <button id="saveAndCreateNewButton" class="submit">Salvar e adicionar novo lançamento</button>
    <button id="saveAndCloseLotButtton" class="submit">Salvar e fechar o lote</button> |
    <button id="deleteButton">Excluir</button>
</p>

@using (Html.BeginForm())
{
    @Html.HiddenFor(model => model.AccountEntryId)
    @Html.HiddenFor(model => model.LotId)
    @Html.HiddenFor(model => model.AccountPlanId)
    @Html.HiddenFor(model => model.SaveMode)
    
    <h3>Detalhes</h3>
    
    @Html.ValidationSummary(true)

        
    <div class="editor-label">
        @Html.LabelFor(model => model.AccountPlanDescription): 
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.AccountPlanDescription, new { size = 56, @class = "search", placeholder = "Pesquisar conta contábil" })
        @Html.ValidationMessageFor(model => model.AccountPlanDescription)
    </div>
    <table style="margin:15px 0 15px 0 ;">
        <tr>
            <td width="130">@Html.LabelFor(model => model.Type): </td>
            <td width="125">@Html.LabelFor(model => model.AccountEntryDate): </td>
            <td>@Html.LabelFor(model => model.Value): </td>
        </tr>
        <tr>
            <td>
                @Html.RadioButtonFor(model => model.Type, "C") <label>Crédito</label>
                @Html.RadioButtonFor(model => model.Type, "D")<label>Débito</label>
            </td>
            <td>@Html.TextBoxFor(model => model.AccountEntryDate, new { @class = "textCalendar", placeholder = "--/--/----" })</td>
            <td>@Html.TextBoxFor(model => model.Value, new { @class = "textMoney", placeholder = "0,00" })</td>
        </tr>
        <tr>
            <td>@Html.ValidationMessageFor(model => model.Type)</td>
            <td>@Html.ValidationMessageFor(model => model.AccountEntryDate)</td>
            <td>@Html.ValidationMessageFor(model => model.Value)</td>
        </tr>

    </table>
    <div class="editor-label">
        @Html.LabelFor(model => model.Description):
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.Description, new { rows = 10, cols = 62, placeholder = "Descrição do lançamento" })
        @Html.ValidationMessageFor(model => model.Description)
    </div>
    
    <h3>Informações do Lote</h3>
    <table width="630">
        <tr>
            <td>@Html.LabelFor(model => model.LotDescription): <a href="@Url.Action("Edit", "Lot", new { Id = Model.LotId})">@Model.LotDescription</a> </td>
            <td>Período: <span class="bold"> @Html.DisplayFor(model => model.LotPeriod)</span></td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.LotTotalCredit): <span class="bold">@Html.DisplayFor(model => model.LotTotalCredit)</span></td>
            <td>@Html.LabelFor(model => model.LotTotalDebit): <span class="bold">@Html.DisplayFor(model => model.LotTotalDebit)</span></td>
        </tr>
    </table>
}

<p>&nbsp;</p>

</div>